package com.belencarrasco.serviciopedidoscliente;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * @author Belen
 *
 */
public class PedidosPendientesAdapter extends ArrayAdapter<Pedido> {

	private Context mContext;
	private List<Pedido> mObjects;

	
	static class ViewHolder {
		public TextView mesa;
		public TextView descripcion;
	}

	/**
	 * @param context
	 * @param textViewResourceId
	 * @param objects
	 */
	public PedidosPendientesAdapter(Context context, int textViewResourceId,
			List<Pedido> objects) {
		super(context, textViewResourceId, objects);
		mContext = context;
		mObjects = objects;
	}

	/* (non-Javadoc)
	 * @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			rowView = inflater.inflate(R.layout.activity_pedidos_item, null);
			ViewHolder viewHolder = new ViewHolder();
			viewHolder.mesa = (TextView) rowView.findViewById(R.id.adapter_act_mesa);
			viewHolder.descripcion = (TextView) rowView.findViewById(R.id.adapter_act_descripcion);
			rowView.setTag(viewHolder);
		}

		ViewHolder holder = (ViewHolder) rowView.getTag();
		holder.mesa.setText(mObjects.get(position).getMesa());
		holder.descripcion.setText(mObjects.get(position).getDescripcion());

		return rowView;
	}
}

